//
//  NSString+SYMD5.m
//  24加密解密作业
//
//  Created by dllo on 16/8/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "NSString+SYMD5.h"
#import <CommonCrypto/CommonCrypto.h>
@implementation NSString (SYMD5)
- (NSString *)stringWith32BitMD5
{
    const char *Cstring = [self UTF8String];
    CC_LONG length = (CC_LONG)strlen(Cstring);
    unsigned char bytes[CC_MD5_DIGEST_LENGTH];
   CC_MD5(Cstring,length,bytes);
    NSMutableString *finalMD5String = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
        [finalMD5String appendFormat:@"%02x",bytes[i]];
    }
    return finalMD5String;
}

- (NSString *)stringWith16BitMD5
{
    NSString *md5String32Bit = [self stringWith32BitMD5];
    NSString *md5String16Bit = [md5String32Bit substringToIndex:md5String32Bit.length - 8];
    md5String16Bit = [md5String16Bit substringFromIndex:8];
    return md5String16Bit;
}


@end
